/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package view;
import controler.Controleur;
import modele.Joueur;

/**
 *
 * @author Vaïk
 */
public class FrameNewPlayer extends javax.swing.JDialog {

    /**
     * Creates new form FrameNewPlayer
     */
    public FrameNewPlayer(Controleur c) 
    {
        setVisible(true);
        initComponents();
        controleur = c;
    }
    
    public FrameNewPlayer(Controleur c, int numJ, int nbJ) 
    {
        initComponents();
        controleur = c;
        
        for(Joueur j : c.getListJoueurs())
        {
            switch(j.getNom())
            {
                case "Julien Nauroy"        : rbJN.setEnabled(false); break;
                case "Claude Barras"        : rbCB.setEnabled(false); break;
                case "Yannis Manoussakis"   : rbYM.setEnabled(false); break;
                case "Joel Falcou"          : rbJF.setEnabled(false); break;
            }
        }
        
        if(rbJN.isEnabled())
        {
            rbJN.setSelected(true);
        }
        else
        {
            rbJN.setSelected(false);
            if(rbCB.isEnabled())
            {
                rbCB.setSelected(true);
            }
            else
            {
                rbCB.setSelected(false);
                if(rbYM.isEnabled())
                {
                    rbYM.setSelected(true);
                }
                else
                {
                    rbYM.setSelected(false);
                    if(rbJF.isEnabled())
                    {
                        rbJF.setSelected(true);
                    }
                }
            }
        }
        
        
        this.numJ = numJ;
        this.nbJ = nbJ;
        jLabel2.setText("Choix du joueur " + numJ + "/" + nbJ + " :");
        setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel2 = new javax.swing.JLabel();
        rbJN = new javax.swing.JRadioButton();
        rbCB = new javax.swing.JRadioButton();
        rbYM = new javax.swing.JRadioButton();
        rbJF = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel2.setText("Choix du joueur :");

        buttonGroup1.add(rbJN);
        rbJN.setSelected(true);
        rbJN.setText("Julien Nauroy");
        rbJN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbJNActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbCB);
        rbCB.setText("Claude Barras");

        buttonGroup1.add(rbYM);
        rbYM.setText("Yannis Manoussakis");

        buttonGroup1.add(rbJF);
        rbJF.setText("Joël Falcou");

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/nauroy.jpg"))); // NOI18N

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/barras.jpg"))); // NOI18N

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/manoussakis.jpg"))); // NOI18N

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/falcou.jpg"))); // NOI18N

        jButton1.setText("Valider");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(13, 13, 13)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(37, 37, 37))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(jLabel5)
                                            .addGap(76, 76, 76))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(rbJN)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(rbCB)))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(rbYM)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(rbJF, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(30, 30, 30))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbJN)
                    .addComponent(rbCB))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbYM)
                    .addComponent(rbJF))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void rbJNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbJNActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_rbJNActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (rbJN.isSelected()) 
        {
            controleur.ajouterJoueur("Julien Nauroy", "/view/nauroyS.jpg", "/view/nauroy.jpg", numJ);
        }
        else if (rbCB.isSelected())
        {
            controleur.ajouterJoueur("Claude Barras", "/view/barrasS.jpg", "/view/barras.jpg", numJ);
        }
        else if (rbYM.isSelected())
        {
            controleur.ajouterJoueur("Yannis Manoussakis", "/view/manoussakisS.jpg", "/view/manoussakis.jpg", numJ);
        }
        else
        {
            controleur.ajouterJoueur("Joël Falcou", "/view/falcouS.jpg", "/view/falcou.jpg", numJ);
        }
        
        
        if (numJ < nbJ)
        {
            new FrameNewPlayer(controleur, ++numJ, nbJ);
            dispose();
        }
        else
        {
            controleur.debutPartie();
            dispose();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JRadioButton rbCB;
    private javax.swing.JRadioButton rbJF;
    private javax.swing.JRadioButton rbJN;
    private javax.swing.JRadioButton rbYM;
    // End of variables declaration//GEN-END:variables

    Controleur controleur;
    int numJ, nbJ;
}
